#include "windowpitch.h"
#include "ui_windowpitch.h"

WindowPitch::WindowPitch(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::WindowPitch)
{
    ui->setupUi(this);
}
WindowPitch::WindowPitch(Pitch & F0, QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::WindowPitch)
{
    ui->setupUi(this);
    ui->qwtPlot_F0->setTitle( "Pitch" );
    ui->qwtPlot_F0->setCanvasBackground( Qt::white );
    ui->qwtPlot_F0->insertLegend( new QwtLegend() );
    setCentralWidget(ui->qwtPlot_F0);
    QwtPlotGrid *grid = new QwtPlotGrid();
    grid->attach( ui->qwtPlot_F0 );

    QwtSymbol *symbol = new QwtSymbol( QwtSymbol::Ellipse,
        QBrush( Qt::yellow ), QPen( Qt::red, 2 ), QSize( 8, 8 ) );

    QPolygonF points;

    QwtPlotCurve *curve = new QwtPlotCurve();
    curve->setStyle(QwtPlotCurve::Dots);

    curve->setSymbol( symbol );
    for(int i = 0; i < F0.candidates.size(); ++ i) {
        points << QPointF( F0.Sampled_indexToX(i), F0.candidates[i].frequnce[0]);
        curve->setSamples( points );
        curve->attach( ui->qwtPlot_F0 );
    }

    QwtPlotZoomer *zoomer = new QwtPlotZoomer( ui->qwtPlot_F0->canvas() );
    // 中键   Undo操作
    zoomer->setMousePattern(QwtEventPattern::MouseSelect3, Qt::MidButton );
    // 中键 + Ctrl Redo操作
    zoomer->setMousePattern(QwtEventPattern::MouseSelect6, Qt::MidButton, Qt::ControlModifier );
    // 中键 + Shift zoom base,即Home操作
    zoomer->setMousePattern(QwtEventPattern::MouseSelect2, Qt::MidButton, Qt::ShiftModifier );
    zoomer->setEnabled(true);
}

WindowPitch::~WindowPitch()
{
    delete ui;
}
